# encoding: UTF-8
import glob as gb
import cv2
import os
import shutil
filecount = 0    #计数文件夹下共有多少个小文件
picturecount =0  #计数图片
picture_number = 0
for filename in os.listdir('../data/'):
    filecount += 1
for i in range(0,filecount):    
    videoWriter = cv2.VideoWriter('../results/'+str(i)+'.mp4', cv2.VideoWriter_fourcc(*'MJPG'), 25, (640,480))
    for picturename in os.listdir('../data/'+str(i)):
        picturecount += 1
    for m in range(1,picturecount+1):
        while (os.path.exists("../data/"+str(i)+"/"+str(picture_number)+".jpg")!=True):
            picture_number += 1
        img  = cv2.imread("../data/"+str(i)+"/"+str(picture_number)+".jpg") 
        #img = cv2.resize(img,(640,480))
        if m!=1:   #检测帧不加入合成视频
            videoWriter.write(img)
        picture_number += 1
    picturecount = 0
    picture_number = 0
    shutil.rmtree("../data/"+str(i))    #递归删除文件夹
    

